#ifndef LINK
#define LINK

#include <iostream>

#define INITIALBITPOSITION  0x80000000

enum LinkComMode {
  SEND,
  RECEIVE,
  COMPLETE,
  RESET,
  DISCONNECTED
};

enum ClockState {
  STATE1,
  STATE2,
  STATE3,
  STATE4,
  STATE5,
  STATE6,
  STATE7,
  STATE8,
  STATE9,
  STATE10,
  STATE11,
  STATE12,
  STATE13,
  STATE14,
  STATE15
};

class Link
{
  
  unsigned int uint32_TargetLabel;
  unsigned int uint32_BuildLabel;
  unsigned int uint32_LabelBitPosition;
  unsigned int uint32_DisplayLabelBitPosition;

  bool * pb_DataLine;
  bool b_DataLineBuffer;
  bool b_LinkResetFromHost;
  bool b_LinkResetFromNeighbor;
  bool b_LinkKilled;

  LinkComMode e_LinkComMode;
  ClockState e_ClockState;

  void IncrementBitPosition(void);
  void ResetBitPosition(void);

public:

  Link(bool * dataLine);
  ~Link(void);

  void ClockLink(void);

  void SetTargetLabel(unsigned int targetLabel);
  void SetLinkResetFromHost(void);

  bool SetCurrentBuilLabelBit(void);

  unsigned int ReadTargetLabel(void);
  unsigned int ReadBuildLabel(void);
  unsigned int ReadLabelBitPosition(void);

  bool GetTargetLabelBit(void);
  bool GetBuildLabelBit(void);
  void SetCurrentBuildLabelBit(void);

  void PrintLinkData(void);

  bool * GetPhysicalLinkAddress(void);

 
  bool ReadResetFromNeighbor(void);

  bool IsLinkActive(void);
  bool IsLinkComplete(void);

};


#endif
